<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            text-decoration: none;
            list-style: none;
        }
        #banner{
            width: 800px;
            height: 400px;
            border: 2px solid #999; 
            overflow: hidden;
            position: relative;
        }
        #imglist{
            width: 4000px;
            height: 400px;
        }
        #imglist img{
            width: 800px;
            height: 400px;
        }
        #imglist li{
            float: left;
        }
        .prev{
            background: #666;
            width: 30px;
            height: 40px;
            color: #fff;
            text-align: center;
            line-height: 40px;
            position: absolute;
            left: 5px;
            top: 45%;
            cursor: pointer;
        }
        .next{
            background: #666;
            width: 30px;
            height: 40px;
            color: #fff;
            text-align: center;
            line-height: 40px;
            position: absolute;
            right: 5px;
            top: 45%;
            cursor: pointer;
        }
        #icolist{
            position: absolute;
            right: 10px;
            bottom: 10px;
        }
        #icolist li{
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background: #666;
            text-align: center;
            line-height: 30px;
            color: #fff;
            float: left;
            margin-left: 5px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="banner">
        <ul id="imglist">
            <li><img src="./1.webp" alt=""></li>
            <li><img src="./2.jpg" alt=""></li>
            <li><img src="./3.webp" alt=""></li>
            <li><img src="./4.jpg" alt=""></li>
            <li><img src="./5.jpg" alt=""></li>
        </ul>
        <ul id="icolist">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <div class="prev">《</div>
        <div class="next">》</div>
    </div>
    <script>
        var eprev = document.querySelector('.prev')
        var enext = document.querySelector('.next')
        var esico = document.getElementById('icolist').getElementsByTagName('li');
        var left = 0;
        var timer;
        run();
        function run(){
            if (left <= -3200){
                left =0;
            }
            imglist.style.marginLeft = left + 'px';
            var n = (left % 800 == 0) ? n=1200 : n = 10;
            left -= 10;
            timer = setTimeout(run,n);
         
            }
            function imgchange(n){
                let lt = - (n * 800);
                imglist.style.marginLeft = lt + 'px';
                left = lt;
        }
        eprev.onclick = function(){
            let prevgo = Math.floor(-left / 800) - 1;
            if (prevgo == -1){
                prevgo = 3;
            }
            imgchange(prevgo);
        }
        enext.onclick = function(){
            let nextgo = Math.floor(-left / 800) + 1;
            if (nextgo == 4){
                nextgo = 0;
            }
            imgchange(nextgo);
        }
    </script>
</body>
</html> 